# coding=utf-8
"""
Author: Mr.夏末
@Function: 12306滑块验证码
"""
from time import sleep
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver import ActionChains

# 使用options，去掉自动化软件控制的标识
option = Options()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_argument('--disable-blink-features=AutomationControlled')

##关掉密码弹窗
prefs = {}
prefs['credentials_enable_service'] = False
prefs['profile.password_manager_enabled'] = False
option.add_experimental_option('prefs', prefs)

driver = webdriver.Chrome(options=option)
driver.implicitly_wait(10)
driver.maximize_window()
#打开12306登录页
driver.get('https://kyfw.12306.cn/otn/resources/login.html')
driver.find_element('xpath','//input[@id="J-userName"]').send_keys('17863087593')
driver.find_element('xpath','//input[@id="J-password"]').send_keys('shuai21654')
driver.find_element('xpath','//a[@id="J-login"]').click()

# 找到滑块
ele1 = driver.find_element('xpath','//span[@id="nc_1_n1z"]')
ele2 = driver.find_element('xpath','//span[@class="nc-lang-cnt"]')
print(ele1.size)
print(ele2.size)


#使用action滑动
action = ActionChains(driver)
#按住滑块
action.click_and_hold(ele1)
#拖到最右边
action.move_by_offset(ele2.size.get('width'),0)
#松开鼠标
action.release()
#让这些动作执行
action.perform()
sleep(2)

driver.quit()